package com.wulian.common.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author FlowerMe on 2017-4-28.
 */
@Data
@ApiModel("返回结果Moudel")
public class AppResultMoudel<T> {

    public static final Integer SUCCESS_FLAG = 0;
    public static final Integer ERROR_FLAG = 1;

    @ApiModelProperty("成功标识：成功 返回status   失败 返回 status 1")
    private Integer code;
    @ApiModelProperty("失败信息")
    private String msg;
    @ApiModelProperty("返回结果数据集")
    private T body;

    public AppResultMoudel() {
    }

    /**
     * 功能描述: <br>
     * 〈只返回code〉
     * @Param:
     * @Return:
     * @Author: caifulin
     * @Date: 2020/5/11
     */
    public AppResultMoudel(Integer code) {
        this.code = code;
    }

    /**
     * 功能描述: <br>
     * 〈返回code加消息〉
     * @Param:
     * @Return:
     * @Author: caifulin
     * @Date: 2020/5/11
     */
    public AppResultMoudel(Integer code,String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 功能描述: <br>
     * 〈返回code加body〉
     * @Param:
     * @Return:
     * @Author: caifulin
     * @Date: 2020/5/11
     */
    public AppResultMoudel(Integer code, T body) {
        this.code = code;
        this.body = body;
    }

    public AppResultMoudel success(T body,String successMsg) {
        this.body = body;
        this.code = SUCCESS_FLAG;
        this.msg = successMsg;
        return  this;
    }
    public AppResultMoudel error(T body,String errorMsg) {
        this.code = ERROR_FLAG;
        this.msg = errorMsg;
        this.body = body;
        return  this;
    }
}
